<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>vue</title>
  </head>
  <script src="../vue-2.6.11.js"></script>
  <body>
    <!-- 模板 -->

    <div id="example">{{ fullName }}</div>

    <script>
      //数据
      let data = {
        firstName: 'Foo',

        lastName: 'Bar'
      }

      //vm实例
      var vm = new Vue({
        el: '#example',

        data: data,

        computed: {
          fullName: {
            // getter
            get: function() {
              return this.firstName + ' ' + this.lastName
            },

            // setter
            set: function(newValue) {
              var names = newValue.split(' ')

              this.firstName = names[0]

              this.lastName = names[names.length - 1]
            }
          }
        }
      })
    </script>
  </body>
</html>
